//获取应用实例
var app = getApp();
Page({
    data: {
	    isShowFootNav: false,
	    platform: "iPhone"
    },
    onLoad: function () {
    	app.setStorageSync(app.globalData.twCallVisaSign,1)  //用于首页是否调用签注类别标记
	    if (app.isAndroid()) {
		    this.setData({platform: "android"});
	    }

	    var data = app.getStorageSync(app.globalData.twCacheOrderPay);
    	console.log(data)
      this.setData({
        totalFee: data.totalFee,
        endorseInfoList: data.endorseInfoList
      });
    },

    toUrl: function (e) {
    	console.log(e.currentTarget.dataset)
      app.setStorageSync(app.globalData.twPassCache,e.currentTarget.dataset.pass)
	    app.navigateTo({url:'../twPassInformation/twPassInformation'})
    },

    formSubmit:function (e) {
        // app.loadToast();
	    var that = this;
      var param = JSON.stringify(app.getStorageSync(app.globalData.twCacheOrderPay));
	    var formResult = {
		    objStr: param,
		    platform: this.data.platform,
		    payType: 3
	    };
        var opt = {
         url: app.globalData.host+"/wx/etw/pay.ajax",
         data: formResult,
         sucFn:function (result) {
              // param['orderId'] = result.body.orderIds[0].id;
              var resObject = result.body.wxPayInfo;
              var res = {
	              timeStamp: resObject.timeStamp,
	              nonceStr: resObject.nonceStr,
	              package: resObject.packageName,
	              signType:resObject.signType,
	              paySign: resObject.paySign,
	              sucFn: function (e) {
                  var opt1 = {
		                  url: app.globalData.host+"/wx/ed/payCallback.ajax",
		                  data: {
		                      orderId: result.body.orderIds[0].chargeOrderId,
			                    prepayId: result.body.wxPayInfo.prepayId,
													moduleOrderId: result.body.orderIds[0].id,
			                    platform: that.data.platform
	                    },
		                  sucFn:function (res) {
			                   app.setStorageSync(app.globalData.twPaySuccess,result.body.orderIds);
			                   app.redirectTo({url:'../twPaysuccess/twPaysuccess'})
                      }
                  }
		              app.ajax(opt1);
	              },
	              failFn: function (e) {
		              console.error('支付失败',e)
	              }
              }
 	            app.requestPayment(res)
         }
        };
        app.ajax(opt);
    }
});
